Bukkit Plugin Tutorial
Hello! This won't be much of an intro because I just want to get right into it. Now, I'm not the best at making plugins, so all I'm showing you is a simple block listener. Things your going to need: *Eclipse *Bukkit Developer API (Get the development build; big red button) Extra resources: *JavaDocs *Official plugin tutorial Step 1! First, You need to install Eclipse. Just drag and drop the contents of the .ZIP to some where in a folder, Nice and simple. Now, Open it. Next, Click 'File->New->Java Project' When the window pops-up, Type in at 'Project name:' your plugin name. Then click 'Finish' Now, Right click your project thats on the left hand side: When the right click box is up, click 'properties'. When the next window has popped up: Thats it for adding the API! Step 2! Next is where you become bored! 'Everything here and in future steps is case sensitive.' To the left, Right click on your plugin folder, Click 'New>>File' In 'File name' type "plugin.yml" and then 'Finish' ////////////////////////////////////////////Hade bara lust...\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Double click on your plugin.yml file and paste this name: main: me... version: 1 author: You will need to replace: * with your preferred username, in lowercase * with the plugin's name, in lowercase * with your username, normal * with your plugin name, should start with a capital letter (doesn't technically need to, but it's recommended) ... in the YML and in all code below. Next right click on 'src' click New->Package and in 'Name' type: me.. Then click 'Finish' Next, Right click on the package you just made and click 'New->Class', At 'Name:', input "" and then click 'Finish' Now copy all this below and most of the lines are explained in the text :D package me..; // These imports can be generated automatically by Eclipse import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; /** * This plugin does something! :O How cool is that * * @author */ public class extends JavaPlugin { @Override public void onEnable() { //When this plugin is enabled.... final PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new Listener(), this); // Get bukkit to send you events to the BlockListener final Logger logger = getLogger(); // Get the console log, save it into "logger" logger.info("You're using my awesome plugin! Updates are at http://derp.com"); // Give the console a friendly message } } Thats all Java :D Just to let you know, You will get an error on 'pm.registerEvents(new Listener(), this);' because the Listener does not exist yet - we will create this in step 3. Step 3! Next, Right click on the package you just made and click 'New->Class', At 'Name:', input "Listener", and then click 'Finish'. Now, copy this into that file: package me..; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; public class Listener implements Listener { @EventHandler // This tells bukkit that you are handling this event. public void onBlockPlace(BlockPlaceEvent event) { // We are handling a BlockPlaceEvent, which happens when a block is placed. (:O) Player player = event.getPlayer(); // Find out the player that caused the event, save it into "player" Block block = event.getBlockPlaced(); // Find out the block that was placed, save it into "block" if (block.getType() Material.TNT && !player.isOp()) { // If the block is TNT and the player is not an Op ( ! means not) player.sendMessage(ChatColor.RED + "You can't place TNT!"); // Sends the player a message, Feel free to change :D event.setCancelled(true); // Remove the block and puts back what was ever there before } } } The magic happens in the 'if' statement :D So when a player places a block of TNT, Its gets taken away (and put back in his inventory) and he gets sent a message. Feel free to add more stuff and take this code and make awesome plugins :D Now, File->Export. select your plugin and Finish, Drag the .JAR into your plugins folder and try it out! Tips *Use "static" sparingly, if at all. *Don't use @SuppressWarnings unless you really know what you're doing. Eclipse will want to insert this sometimes, but usually it means you did something wrong - and putting that line of code there just tells Eclipse to stop telling you it's wrong and pretend it's not. It's a bad thing. *"final" is usually a good thing. **as is "private", where possible. Note that your event handlers should be public so that bukkit can send events to them. *Learn Java - without this, you won't be going anywhere fast. *Modify other plugins! Find a plugin you like, dig around to see if you can find its source, and see what you can change in it. On the way you'll learn a lot more about what plugins do and how they accomplish various tasks. *Don't be afraid to make new classes. *If I ever see "private final HashMap debugees" in anyone's code I shall flip. ... *Always use the "reload" command.